
/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/jjaehuny/user');
var jjaehuny = require('./routes/jjaehuny/jjaehuny');
var mongo = require('./routes/jjaehuny/mongo');
var redis = require('./routes/jjaehuny/redis');
var database = require('./routes/jjaehuny/database');
var TestServer = require('./routes/jjaehuny/TestServer');
var RealServer = require('./routes/jjaehuny/RealServer');
var guild = require('./routes/jjaehuny/guild');

var http = require('http');
var path = require('path');
var fs = require('fs');
var util = require('util');

var app = express();

// all environments
app.set('Test_Game_Master', database.Test_Game_Master);
app.set('Real_Game_Backup', database.Real_Game_Backup);
app.set('Test_Log_Master', database.Test_Log_Master);
app.set('Real_Log_Backup', database.Real_Log_Backup);

app.set('Real_Game_Master', database.Real_Game_Master);

app.set('Test_Redis_Master', redis.Test_Redis_Master);
app.set('Real_Redis_Master', redis.Real_Redis_Master);
app.set('Test_Redis_Guild_Master', redis.Test_Redis_Guild_Master);


app.set('Test_mongodb_log_pvp_play', mongo.Test_mongodb_log_pvp_play);
app.set('Real_mongodb_log_pvp_play', mongo.Real_mongodb_log_pvp_play);

app.set('Test_Guild_Master', database.Test_Guild_Master);
app.set('Real_Guild_Master', database.Real_Guild_Master);

app.set('port', process.env.PORT || 54000);
app.set('views', path.join(__dirname, 'views'));

app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());

//app.use(express.cookieDecoder());
//app.use(express.session());

app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

//app.use(express.cookieSession({ secret: 'secret', cookie: { maxAge: 60 * 60 * 1000 }});
//app.use(express.bodyParser());
//app.use(function (req, res, next) {
//    // check if client sent cookie
//    var cookie = req.cookies.server;
//    if (cookie === undefined)
//    {
//        // no: set a new cookie
//        res.cookie('server','Test');
//        console.log('cookie have created successfully');
//    }
//    else
//    {
//        // yes, cookie was already present
//        console.log('cookie exists', cookie);
//    }
//    next(); // <-- important!
//});

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);

app.get('/jjaehuny_starup', routes.jjaehuny_starup);
app.get('/jjaehuny_test', jjaehuny.test);


app.get('/startup_test', jjaehuny.startup_test);
app.get('/jjaehuny_old', jjaehuny.jjaehuny_old);

app.get('/Test_showTables', TestServer.Test_showTables);
app.get('/Test_showTables/:tableName', TestServer.Test_showTable);

app.get('/Test_showCurrentUser', TestServer.Test_showCurrentUser);
app.get('/Test_showWorldBossRank', redis.Test_showWorldBossRank);
app.get('/Test_showGuildRank', redis.Test_showGuildRank);

app.get('/Test_find_info_login_socialid/:socialid', TestServer.Test_find_info_login_socialid);
app.get('/Test_find_info_login_seq/:seq', TestServer.Test_find_info_login_seq);

app.get('/Test_find_info_user_socialid/:socialid', TestServer.Test_find_info_user_socialid);
app.get('/Test_find_info_user_seq/:seq', TestServer.Test_find_info_user_seq);
app.get('/Test_find_info_user_nickname/:nickname', TestServer.Test_find_info_user_nickname);
app.get('/Test_find_info_character_user_seq/:user_seq', TestServer.Test_find_info_character_user_seq);
app.get('/Test_find_info_character_seq/:seq', TestServer.Test_find_info_character_seq);

app.get('/Test_find_guild_info_name/:name', guild.Test_find_guild_info_name);


app.get('/Test_update_env_block/:block', TestServer.Test_update_env_block);
app.get('/Test_update_contents_open/:content&:onoff', TestServer.Test_update_contents_open);
app.get('/Test_update_vip/:seq&:point', TestServer.Test_update_vip);


app.get('/Test_FlushAll', redis.Test_FlushAll);

app.get('/GuildRank_FlushAll', redis.Test_GuildRank_FlushAll);



app.get('/Real_showTables', RealServer.Real_showTables);
app.get('/Real_showTables/:tableName', RealServer.Real_showTable);
app.get('/Real_showCurrentUser', RealServer.Real_showCurrentUser);
app.get('/Real_showWorldBossRank', redis.Real_showWorldBossRank);

app.get('/Real_find_info_login_socialid/:socialid', RealServer.Real_find_info_login_socialid);
app.get('/Real_find_info_login_seq/:seq', RealServer.Real_find_info_login_seq);

app.get('/Real_find_info_user_socialid/:socialid', RealServer.Real_find_info_user_socialid);
app.get('/Real_find_info_user_seq/:seq', RealServer.Real_find_info_user_seq);
app.get('/Real_find_info_user_nickname/:nickname', RealServer.Real_find_info_user_nickname);
app.get('/Real_find_info_character_user_seq/:user_seq', RealServer.Real_find_info_character_user_seq);
app.get('/Real_find_info_character_seq/:seq', RealServer.Real_find_info_character_seq);

app.get('/Real_find_guild_info_name/:name', guild.Real_find_guild_info_name);


app.get('/Real_update_env_block/:block', RealServer.Real_update_env_block);
app.get('/Real_update_contents_open/:content&:onoff', RealServer.Real_update_contents_open);

app.post('/Real_lastlogin_to_buyitem', RealServer.Real_lastlogin_to_buyitem);


app.get('/Real_FlushAll', redis.Real_FlushAll);





app.get('/showTables/:server', user.showTables);
app.get('/selectTable/:server&:tableName', user.showTable);
app.get('/selectTable_guild/:server&:tableName', user.showTable_guild);

app.get('/showConnection/:server', user.showConnection);

app.get('/findFromSocialid/:server&:socialid', user.findFromSocialid);
app.get('/info_login_findFromseq/:server&:seq', user.info_login_findFromseq);
app.get('/info_user_findFromSocialid/:server&:socialid', user.info_user_findFromSocialid);
app.get('/findFromSeq/:server&:seq', user.findFromSeq);
app.get('/findFromNickname/:server&:nickname', user.findFromNickname);

//app.get('/showWorldBossRank/:server', redis.showWorldBossRank);

app.get('/update_env_config_block/:server&:block', user.update_env_config_block);

app.get('/update_resource_contents_open/:server&:content&:open', user.update_resource_contents_open);

app.get('/getPVPInfo/:server&:seq', user.getPVPInfo);
app.get('/pvpCount/:server&:seq', mongo.pvpCount);


app.get('/updateVIPPoint/:server&:seq&:point', user.updateVIPPoint);

app.get('/Test_showTables_guild', guild.Test_showTables);
app.get('/Test_showTables_guild/:tableName', guild.Test_showTable);

app.get('/Real_showTables_guild', guild.Real_showTables);
app.get('/Real_showTables_guild/:tableName', guild.Real_showTable);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
